import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'root',
      redirect: '/login'
    },
    {
      path: '/noPermission',
      name: 'noPermission',
      component: () => import('@/layouts/noPermission.vue')
    },
    {
      path: '/admin',
      name: 'admin',
      component: () => import('@/views/admin/adminView.vue'),
      children: [
        {
          path: '/admin/problem',
          name: 'adminProblem',
          component: () => import('@/views/admin/problemAdminView.vue')
        },
        {
          path: '/admin/user',
          name: 'adminUser',
          component: () => import('@/views/admin/userAdminView.vue')
        },
        {
          path: '/admin/exam',
          name: 'adminExam',
          component: () => import('@/views/admin/examAdminView.vue')
        },
        {
          path: '/admin/rolePower',
          name: 'rolePower',
          component: () => import('@/views/admin/rolePowerAdminView.vue')
        },
        {
          path: '/admin/exam/creatExam',
          name: 'creatExam',
          component: () => import('@/views/admin/createExamAdminView.vue'),
          props: (route) => ({ examId: route.query.examId || null })
        },
        {
          path: '/admin/exam/examDate/:examId',
          name: 'examDate',
          component: () => import('@/views/admin/examDateAdminView.vue'),
          props: true
        },
        {
          path: '/admin/exam/examPeopleJudge/:examId/:problemId',
          name: 'peopleProblem',
          component: () => import('@/views/admin/peopleProblemView.vue'),
          props: true
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/loginView.vue'),
      props: (route) => ({ userId: route.query.userId || null })
    },
    {
      path: '/testing/:testId',
      name: 'testing',
      component: () => import('@/views/test/testingView.vue'),
      props: true
    },
    {
      path: '/examing/:examId',
      name: 'examing',
      component: () => import('@/views/exam/examingView.vue'),
      props: true
    },
    {
      path: '/index',
      name: 'index',
      component: () => import('@/layouts/index.vue'),
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('@/views/home/homeView.vue')
        },
        {
          path: '/exam',
          name: 'exam',
          component: () => import('@/views/exam/exam.vue')
        },
        {
          path: '/test',
          name: 'test',
          component: () => import('@/views/test/testView.vue')
        },
        {
          path: '/problems',
          name: 'problems',
          component: () => import('@/views/problems/problemsView.vue')
        },
        {
          path: '/test/startProblem',
          name: 'startProblem',
          component: () => import('@/views/test/son/startProblemView.vue')
        },
        {
          path: '/test/startTest',
          name: 'startTest',
          component: () => import('@/views/test/son/startTestView.vue')
        },
        {
          path: '/user/:userId',
          name: 'user',
          component: () => import('@/views/user/userView.vue'),
          props: true
        },
        {
          path: '/class',
          name: 'class',
          component: () => import('@/views/class/classView.vue')
        }
      ]
    }
  ]
})

export default router